#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<pthread.h>
#include "threadpool.h"

void sys_error(const char *str) 
{
    perror(str);
    exit(1);
}

// 执行的任务, 简单的打印传入的参数 
void taskFunction(void *arg)
{
    int i = (int)arg; 
    sleep(1);
    printf("taskFunction : %d\n", i); 
    return; 
}

int main(int argc, char *argv[])
{
    ThreadPool *pool = getThreadPool(2, 10, 100); 
    if(!pool) sys_error("getThreadPool error"); 
    
    for(int i = 0; i < 100; ++i) 
        addTask(pool, taskFunction, (void*)i);
    
    sleep(30); 

    printf("pool->livenum = %d\n", getLiveNum(pool));
    delThreadPool(pool); 
    printf("end of main\n"); 
    pthread_exit(NULL);
}
